package com.fhj.movie.activity;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONObject;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.NetworkImageView;

import com.fhj.movie.entity.HyyGuanShangZhiNanEntity;
import com.fhj.movie.interfaces.CallbackInterface;
import com.fhj.movie_fhj_01.R;
import com.fhj.utils.CacheUtils;
import com.fhj.utils.HttpConnectionUtils;
import com.fhj.utils.JsonUtils;
import com.lidroid.xutils.BitmapUtils;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class HyyGuanYingZhiNanActivity extends Activity implements OnItemClickListener {
	private ListView listView;
	
	private BitmapUtils bitmapUtils;
	
	private List<HyyGuanShangZhiNanEntity> list;
	
	private MyAdapter adapter;
	
	private Animation loadAnimation;

	private ImageView xuanzhuan;
	
	private TextView wenzi; 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_guan_yang_zhi_nan);
		list=new ArrayList<HyyGuanShangZhiNanEntity>();
		bitmapUtils=new BitmapUtils(this);
		listView=(ListView) findViewById(R.id.guan_ying_listview);
		xuanzhuan=(ImageView)findViewById(R.id.guanshangzhinanXuanzhuan);
		wenzi=(TextView)findViewById(R.id.guanshangzhinanwenzi);
		adapter= new MyAdapter();
		loadAnimation = AnimationUtils.loadAnimation(this, R.anim.taste);
		LinearInterpolator lir = new LinearInterpolator();
		loadAnimation.setInterpolator(lir);
		xuanzhuan.startAnimation(loadAnimation);
		HttpConnectionUtils.getActivityOptionData(this, 3,440300,
				new CallbackInterface() {

					@Override
					public void JsonCallback(JSONObject object) {
						// TODO Auto-generated method stub
						xuanzhuan.clearAnimation();
						xuanzhuan.setVisibility(View.INVISIBLE);
						wenzi.setVisibility(View.INVISIBLE);
						Log.i("", "---------------------->>"+object.toString());
						list=JsonUtils.parseGuanSHnagZhiNangData(object);
						adapter.notifyDataSetChanged();
					}});
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(this);
					
	}
	class MyAdapter extends BaseAdapter {

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return list.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return list.get(position);
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			// TODO Auto-gehonerated method stub
			ViewHolder holder = null;
			if (convertView == null) {
				holder = new ViewHolder();
				convertView = LayoutInflater.from(HyyGuanYingZhiNanActivity.this).inflate(
						R.layout.fragment_lhuo_dong_list_tem, parent, false);
				holder.item_image = (ImageView) convertView
						.findViewById(R.id.item_image);
				holder.item_title = (TextView) convertView
						.findViewById(R.id.item_title);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			String url = list.get(position).getPicUrl();
			holder.item_image.setImageResource(R.drawable.place_holder_h);
			// TODO 下载图片
			if (url != null) {
				bitmapUtils.display(holder.item_image, url);
			}
			holder.item_title.setText(list.get(position).getTitle());

			return convertView;
		}

	}

	class ViewHolder {
		public ImageView item_image;
		public TextView item_title;
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		// TODO Auto-generated method stub
		Intent intent = new Intent(HyyGuanYingZhiNanActivity.this, HyyItemClick.class);
		intent.putExtra("title", list.get(position).getTitle());
		intent.putExtra("clickUrl", list.get(position).getClickUrl());
		startActivity(intent);
	}

}
